/**
 * Created by liyun on 2015/10/27.
 */
var fs = require("fs");
var debug = require('debug')('routes:applyfor');
require('date-utils');
var applyfor = require('../models/applyfor').applyfor;

module.exports = function (app) {

    app.get('/applyfor/list', list);

    app.post('/applyfor/update',update);


};

function list(req,res){
    var pagenum =1;
    if(req.query.page){
        pagenum = req.query.page;
    }
    getApplyfor(pagenum,req,res);

};



function update(req,res){
    var body = req.body;
    new applyfor().edit(body,function(result){
        res.send(result);
    });
};

function getApplyfor(pagenum,req,res){
    var page = ['requirement.createtime','desc',(Number(pagenum)-1)*3,3];//Ĭ��createtime����ÿҳ6��

    new applyfor().list(page,function(data){
        debug(data);
        if(req.query.page){
            res.send(data);
        }else{
            res.render('shop/applyfor_list',{data:data});
        }
        //
    });
}